<?php

namespace app\api\model;

use think\Model;

class BaseModel extends Model
{
    /**
     * 模型字段读取器,拼接图片地址
     * @param $value
     * @return string
     */
    protected function prefixImg($value,$data)
    {
        $finalUrl = $value;
        if ($data['from'] ==1){
            $finalUrl = config('setting.img_prefix').$value;
        }elseif ($data['from'] == 2){
            $finalUrl = config('setting.remote_img_url').$value;
        }
        return $finalUrl;
    }

    /**
     * 模型字段读取器，拼接视频地址
     * @param $value
     * @param $data
     * @return string
     */
    protected function prefixVideo($value,$data){
        $finalUrl = $value;
        if ($data['from'] ==1){
            $finalUrl = config('setting.url_prefix').$value;
        }elseif ($data['from'] == 2){
            $finalUrl = config('setting.remote_img_url').$value;
        }
        return $finalUrl;
    }

    /**
     * 模型字段读取器，拼接音频地址
     * @param $value
     * @param $data
     * @return string
     */
    protected function prefixAudio($value,$data){
        $finalUrl = $value;
        if ($data['from'] ==1){
            $finalUrl = config('setting.url_prefix').$value;
        }elseif ($data['from'] == 2){
            $finalUrl = config('setting.remote_img_url').$value;
        }
        return $finalUrl;
    }
}
